|
|
|
| Try Out the Property Let 1. Modify the code in the cmdDisplay_Click() event of the command button to set the FirstName and LastName properties as shown in the following code: | | Private Sub cmdDisplay_Click()
Dim oEmp As Employee
Set oEmp = New Employee
oEmp.FirstName = "Bill"
oEmp.LastName = "Gates"
MsgBox oEmp.LastName & ", " & oEmp.FirstName End Sub |  | Visual Basic looks at the line of code that contains the call to a property of one of your objects to decide whether it should call Property Get or Property Let. If the property name is on the right side of an expression, it invokes Property Get. If the property name is on the left side of an expression, it invokes Property Let. |
|
 |
|
|
|
|
TIP A Property Let procedure is like a Sub procedure that does not return a value. |
|
|
|
|
|
|
|
|
Creating Property Get and Property Let Procedures |
|
|
|
|
|
|
|
|
Instead of typing in the Property Get and Property Let procedures by hand, you can have the Visual Basic design environment create them for you. When you choose the Tools, Add Procedure menu item, youll be prompted for a procedure name, as well as what type of procedure you want to create. Type in a name and then select a property procedure type. When you click the OK button, the two procedures are generated in the CLS module you have currently selected in the design environment. No code is generated in the procedures, but the two stubs are created for you. |
|
|
|
|
|